package org.wyn.util;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.wyn.constant.Constant;

public class UserCookie {
	public static void addUserId(String value, int age, HttpServletRequest request, HttpServletResponse response){
		CookieTool.setCookie(Constant.USER_USER_ID, value, age, request, response);
	}
	public static String getUserId(HttpServletRequest request) {
		try {
			return CookieTool.getCookie(Constant.USER_USER_ID, request);
		} catch (Exception e) {
			return "";
		}
	}
	public static void deleteUserId(HttpServletRequest request, HttpServletResponse response) {
		CookieTool.deleteCookie(Constant.USER_USER_ID, request, response);
	}

	public static void addUserPassword(String value, int age, HttpServletRequest request, HttpServletResponse response){
		CookieTool.setCookieSecurity(Constant.USER_PASSWORD, value, age, request, response);
	}
	public static void deleteUserPassword(HttpServletRequest request, HttpServletResponse response) {
		CookieTool.deleteCookie(Constant.USER_PASSWORD, request, response);
	}
	public static String getUserPassword(HttpServletRequest request){
		try {
			return CookieTool.getCookieSecurity(Constant.USER_PASSWORD, request);
		} catch (Exception e) {
			return "";
		}
	}

	public static void setLoginStatus(boolean status, HttpServletRequest request, HttpServletResponse response){
		String sts = status ? Constant.USER_LOGIN : Constant.USER_UNLOGIN;
		CookieTool.setCookie(Constant.USER_STATUS, sts, 10 * 60 * 60, request, response);
	}
	public static boolean isLoginStatus(HttpServletRequest request){
		try {
			String status = CookieTool.getCookie(Constant.USER_STATUS, request);
			if(Constant.USER_LOGIN.equals(status)){
				return true;
			}
			return false;
		} catch (Exception e) {
			return false;
		}
	}
}
